package com.oneinlet

import org.junit.Test
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

/**
 * Created by WangZiHe on 19-6-10
 * QQ/WeChat:648830605
 * QQ-Group:368512253
 * Blog:www.520code.net
 * Github:https://github.com/yancheng199287
 */

class TestYCLocalTime {

    @Test
    fun toDefaultFormatNow() {
        println("获取当前默认的时间格式：${YCLocalDateTime.toDefaultFormatNow()}")
    }

    @Test
    fun formatDefault() {
        //val timeStr = "2019-03-06 10:22:56"
        val localDateTime = LocalDateTime.now()
        val localDateTimeStr = YCLocalDateTime.formatDefault(localDateTime)
        println(localDateTimeStr)
        println(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
        println("默认格式化时间：${DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(localDateTime)}")
    }

    @Test
    fun parserDefault() {
        val localDateTimeStr = "2019-06-21 11:34:08"
        val localDateTime = YCLocalDateTime.parserDefault(localDateTimeStr)
        val localDateTime1 = YCLocalDateTime.parser(localDateTimeStr, "yyyy-MM-dd HH:mm:ss")
        println("解析时间：$localDateTime $localDateTime1")
    }

    @Test
    fun subBetweenTime() {
        val localDateTime1 = LocalDateTime.of(2019, 6, 21, 11, 33, 20)
        val localDateTime2 = LocalDateTime.of(2019, 6, 21, 12, 0, 50)
        val count = YCLocalDateTime.subBetweenTime(localDateTime1, localDateTime2, YCLocalDateTime.TimeUnit.SECOND)
        println("两个时间的差值：$count")
    }

    @Test
    fun getTimeNodeWithDay() {
        val localDateTime = LocalDateTime.now()
        val localDateTimeStartNode = YCLocalDateTime.getTimeNodeWithDay(localDateTime, YCLocalDateTime.TimeNode.START)
        val localDateTimeEndNode = YCLocalDateTime.getTimeNodeWithDay(localDateTime, YCLocalDateTime.TimeNode.END)

        val localDateTimeStartStr = YCLocalDateTime.formatDefault(localDateTimeStartNode)

        val localDateTimeEndStr = YCLocalDateTime.formatDefault(localDateTimeEndNode)
        println("格式化时间：$localDateTimeStartStr   $localDateTimeEndStr")
    }

    @Test
    fun secondToTime() {
        val localDateTimeStr = YCLocalDateTime.secondToTime(60 * 24 * 60 * 2 * 10 + 1)
        println("格式化时间：$localDateTimeStr")
    }


    @Test
    fun timeAtBetween() {
        val localDateTime = LocalDateTime.now()
        val localDateTime1 = LocalDateTime.of(2019, 6, 21, 11, 33, 20)
        val localDateTime2 = LocalDateTime.of(2019, 6, 21, 13, 50, 50)
        val isExistInterval = YCLocalDateTime.timeAtBetween(localDateTime, localDateTime1, localDateTime2)
        println("当前时间是否在二者时间之内：$isExistInterval")
    }

}